package com.ldc.wandroid.ui.fragments;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ldc.common.mvvm.BaseMvvmFragment;
import com.ldc.common.utils.ViewModelUtils;
import com.ldc.wandroid.databinding.FragmentHomeBinding;
import com.ldc.wandroid.model.BannerModel;
import com.ldc.wandroid.viewmodel.HomeViewModel;

import java.util.List;


public class HomeFragment extends BaseMvvmFragment<FragmentHomeBinding, HomeViewModel> {

    @Override
    public void onDestroy() {
        super.onDestroy();
        viewModel.getBanner().removeObserver(this::bannerData);
    }

    public static HomeFragment newInstance() {
        Bundle args = new Bundle();
        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected FragmentHomeBinding initViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return FragmentHomeBinding.inflate(inflater, container, false);
    }


    @Override
    protected void main(Bundle savedInstanceState) {
        // 加载数据
        viewModel.getBanner().observeForever(this::bannerData);
        viewModel.loadBanner();

    }

    @Override
    protected HomeViewModel initViewModel() {
        return ViewModelUtils.getViewModel(this, HomeViewModel.class);
    }


    private void bannerData(List<BannerModel> bannerModels) {
    }
}
